import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:thatsfelix/utils/Global.dart';
import 'package:thatsfelix/utils/ScreenAdapter.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePage createState() => _HomePage();
}

class _HomePage extends State<HomePage> {
  final PageController _controller = PageController(
    initialPage: 0,
  );
  final List<String> _swiperImageUrls = [
    "http://pic.netbian.com/uploads/allimg/180912/223122-1536762682439c.jpg",
    "http://pic.netbian.com/uploads/allimg/170920/181748-150590266814b1.jpg",
    "http://pic.netbian.com/uploads/allimg/170828/105247-15038887672985.jpg",
  ];
  double _appBarOpacity = 0;

  void _onScroll(offset) {
    print(offset);
    double opacity = offset / 100;
    if (opacity < 0) {
      opacity = 0;
    } else if (opacity > 1) {
      opacity = 1;
    }
    setState(() {
      _appBarOpacity = opacity;
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: Stack(
        children: <Widget>[
          NotificationListener(
            // ignore: missing_return
            onNotification: (scrollNotification) {
              if (scrollNotification is ScrollUpdateNotification &&
                  scrollNotification.depth == 0) {
                _onScroll(scrollNotification.metrics.pixels);
              }
            },
            child: ListView(
              padding: EdgeInsets.zero,
              children: <Widget>[
                Container(
                  height: ScreenAdapter.width(320),
                  child: Swiper(
                    key: UniqueKey(),
                    itemCount: _swiperImageUrls.length,
                    autoplay: true,
                    itemBuilder: (BuildContext context, int index) {
                      return Image.network(_swiperImageUrls[index],
                          fit: BoxFit.cover);
                    },
                    pagination: SwiperPagination(),
                  ),
                ),
                Container(
                  height: 800,
                  color: Colors.greenAccent,
                  child: Text("首页"),
                )
              ],
            ),
          ),
          Opacity(
            opacity: _appBarOpacity,
            child: Container(
              padding: EdgeInsets.only(top: Global.topBloodHeight),
              height: 50 + Global.topBloodHeight,
              decoration: BoxDecoration(color: Colors.white),
              child: Center(
                  child: Text(
                "首页",
                style: TextStyle(fontSize: 16),
              )),
            ),
          )
        ],
      ),
    );
  }
}
